import React, {useState} from "react"
import {Button, ButtonProps} from "antd";

export interface LoadableButtonProps extends ButtonProps{
    onClick:(event: React.MouseEvent<HTMLElement>) => Promise<any>
}

const LoadableButton: React.FC<LoadableButtonProps> = (props) => {
    const [loading,setLoading] = useState(false)
    return (
        <>
            <Button {...props} loading={loading} onClick={(event: React.MouseEvent<HTMLElement>) =>{
                setLoading(true)
                props.onClick(event).finally(()=>{
                    setLoading(false)
                })
            } }></Button>
        </>
    )
}

export default LoadableButton
